package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EquipManager;
import com.ruoyi.system.service.IEquipManagerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * managerController
 * 
 * @author ruoyi
 * @date 2023-12-17
 */
@RestController
@RequestMapping("/system/manager")
public class EquipManagerController extends BaseController
{
    @Autowired
    private IEquipManagerService equipManagerService;

    /**
     * 查询manager列表
     */
    @PreAuthorize("@ss.hasPermi('system:manager:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipManager equipManager)
    {
        startPage();
        List<EquipManager> list = equipManagerService.selectEquipManagerList(equipManager);
        return getDataTable(list);
    }

    /**
     * 导出manager列表
     */
    @PreAuthorize("@ss.hasPermi('system:manager:export')")
    @Log(title = "manager", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipManager equipManager)
    {
        List<EquipManager> list = equipManagerService.selectEquipManagerList(equipManager);
        ExcelUtil<EquipManager> util = new ExcelUtil<EquipManager>(EquipManager.class);
        util.exportExcel(response, list, "manager数据");
    }

    /**
     * 获取manager详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:manager:query')")
    @GetMapping(value = "/{equipId}")
    public AjaxResult getInfo(@PathVariable("equipId") Long equipId)
    {
        return AjaxResult.success(equipManagerService.selectEquipManagerByEquipId(equipId));
    }

    /**
     * 新增manager
     */
    @PreAuthorize("@ss.hasPermi('system:manager:add')")
    @Log(title = "manager", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipManager equipManager)
    {
        return toAjax(equipManagerService.insertEquipManager(equipManager));
    }

    /**
     * 修改manager
     */
    @PreAuthorize("@ss.hasPermi('system:manager:edit')")
    @Log(title = "manager", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipManager equipManager)
    {
        return toAjax(equipManagerService.updateEquipManager(equipManager));
    }

    /**
     * 删除manager
     */
    @PreAuthorize("@ss.hasPermi('system:manager:remove')")
    @Log(title = "manager", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipIds}")
    public AjaxResult remove(@PathVariable Long[] equipIds)
    {
        return toAjax(equipManagerService.deleteEquipManagerByEquipIds(equipIds));
    }
}
